package cn.wzvtc.soft14;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * Created by linji on 2016/3/4.
 */
@RestController //控制器
@EnableAutoConfiguration
@ComponentScan
@CrossOrigin(origins = {},methods = {RequestMethod.GET,RequestMethod.POST,RequestMethod.OPTIONS})
public class Test {
    public static void main(String[] args) throws Exception {
        SpringApplication.run(Test.class, args);
    }

    @Autowired
    KebiaoService kebiaoService;//new KebiaoService();


    @RequestMapping("/getkebiaobyweekclass")
    Object getkebiaobyweekclass(int week,String clazz) {

        return this.kebiaoService.getKebiao(week,clazz);

    }

    //@RequestMapping("/getlesson")

    @RequestMapping(value="/getlesson",produces = "application/json; charset=UTF-8")
    Object getlesson(){
        return "[{\"name\":\"动态编程\"},{\"name\":\"数据分析\"},{\"name\":\"移动应用\"}]";
    }


    @RequestMapping(value = "/sqlsave")
    Object getlessonke(){
        //UUID.randomUUID().toString()
        Ke k=new Ke();
        k.setId("he");
        k.setName("hha");
        kebiaoService.save(k);
        return null;
    }


    @RequestMapping("/home")
    @ResponseBody
    public Object setuForm(@RequestParam("studentID") String studentID,@RequestParam("studentPass") String studentPass) {
         boolean result=true;
        OldJdbcImpl a=new OldJdbcImpl();
        List list=a.findAllPerson();
        student_info b=(student_info)list.get(0);
        if((studentID.equals(b.studentid))&&(studentPass.equals(b.studentpass)))
        {
            System.out.println("登陆成功!");
            result=true;
        }

        else
        {
            System.out.println("登陆失败!");
            result=false;
        }
        return result;
    }

    @RequestMapping(value = "/register")
    @ResponseBody
    public Object setupForm(@RequestParam("studentID") String studentID,@RequestParam("studentPass") String studentPass ) {
        boolean result=true;
        OldJdbcImpl a=new OldJdbcImpl();
        a.insertPerson(UUID.randomUUID().toString(),studentID,studentPass);
        return result;
    }

}
